package easy

import "unicode"

func MostCommonWord(paragraph string, banned []string) string {
	ban := map[string]bool{}
	for _, s := range banned {
		ban[s] = true
	}
	freq := map[string]int{}
	var word []byte
	for i := 0; i <= len(paragraph); i++ {
		if i < len(paragraph) && unicode.IsLetter(rune(paragraph[i])) {
			word = append(word, byte(unicode.ToLower(rune(paragraph[i]))))
		} else if word != nil {
			s := string(word)
			if !ban[s] {
				freq[s]++
			}
			word = nil
		}
	}
	maxCount := 0
	var res string
	for key, val := range freq {
		if val > maxCount {
			maxCount = val
			res = key
		}
	}
	return res
}
